/**
 * 后台服务接口
 */
import axios from '@/http/index.js'
import qs from 'qs'

/**
 * JSON方式请求参数登录
 * @param {*} username 用户名
 * @param {*} password 密码
 */
export const login = (username,password) => {
  return axios({
    method: 'post',
    url: '/auth/login',
    data: {username,password,type:'password'}
  })
}

/**
 * 表单方式请求参数登录
 * @param {*} username 用户名
 * @param {*} password 密码
 */
export const fromLogin = (username,password) => {
  return axios({
    method: 'post',
    url: '/login',
    data: qs.stringify({username,password})
  })
}

/**
 * 获取用户信息
 * @param {*} userId 用户id
 */
export const getUserInfo = userId => {
  return axios({
    method: 'get',
    url: '/user/'+userId
  })
}

export const getConfigName = () => {
  return axios({
    method: 'get',
    url: '/config/getAllConfigName'
  })
}

export const getAllConfig = () => {
  return axios({
    method: 'get',
    url: '/config/getAllConfig'
  })
}

//getConfigByName
export const getConfigByName = (name) => {
  return axios({
    method: 'get',
    url: '/config/getConfigByName?name='+name
  })
}

//getConfigByKey
export const getConfigByKey = (name,key) => {
  return axios({
    method: 'get',
    url: '/config/getConfigByKey?name='+name+'&key='+key
  })
}

// deleteConfig
export const deleteConfig = (name,key) => {
  return axios({
    method: 'delete',
    url: '/config/deleteConfig?name='+name+'&key='+key
  })
}

// updateConfig
export const updateConfig = (name,key,value) => {
  return axios({
    method: 'post',
    url: '/config/updateConfig',
    data: {name,key,value}
  })
}

// addName
export const addName = (name,desc) => {
  return axios({
    method: 'post',
    url: '/config/addName',
    data: {name,desc}
  })
}

// addConfig
export const addConfig = (name,key,value) => {
  return axios({
    method: 'post',
    url: '/config/addConfig',
    data: {name,key,value}
  })
}

// queryConfig
export const queryConfig = (name,key) => {
  return axios({
    method: 'get',
    url: '/config/queryConfig?name='+name+"&key="+key
  })
}